<?php
/**
 * Created by Engineer CuiLiwu.
 * Project: deal.
 * Date: 2018/6/23-13:47
 * License Hangzhou orce Technology Co., Ltd. Copyright © 2018
 */

namespace App\Http\Controllers\Web\Member\Buyer;

use App\Http\Controllers\Web\BaseController;
use Illuminate\Http\Request;


// 找资质，服务订单。买家管理控制器。
class ServiceOrdersBakController  extends BaseController
{
    protected $api_url = [
        'index' => ['get',  'buyer/service/orders'],
        'show'  => ['get',  'buyer/service/orders/%d'],
        'store' => ['post', 'buyer/service/orders'],
        'update'=> ['put',  'buyer/service/orders/%d'],
        // 'delete'=> ['delete', ''],
    ];

    protected $request;

    public function __construct(Request $request)
    {
        $this->request = $request;
    }

    public function index(){
        dd('进入错误的页面');
        //参数部分
        $search_params = $this->request->all(['service_code', 'created_at','status','keyword']);
//        dd($search_params);
        $page = $this->request->get('page', 1);
        $params = [
            'search' => search_params($search_params),
            'searchJoin' => 'and',
            'page' => $page,
            'with' => 'service_detail;user;shop',
            'orderBy'=>'id',
            'sortedBy'=>'desc',
        ];
        //请求部分
        $ret = http_web($this->api_url['index'])->send($params);

        //结果处理部分
        $data = paginate($this->request, $ret['data']);

        //回填搜索框值
        $data['search_params'] = $search_params;

        return view('web.user.buyer.service_orders', $data);
    }

    /**
     *  修改 备注
     * */
    public function update($id){

        $this->validate($this->request, [
            //'expect_date' => 'required|date_format:Y/m/d',// 期望交付时间
            'remark' => 'required'// 备注信息
        ]);
        
        //参数部分
        $validate = $this->request->all(['expect_date', 'remark']);
        
        $params = [
            'id'=>$id,
            'expect_date'=>$validate['expect_date'],
            'remark'=>$validate['remark'],
        ];

        //请求部分
        $ret = http_web($this->api_url['update'],[$id])->send($params);

        //结果处理部分
        return $ret;
    }
}